export class UtilComponent {
  static getColor16ByText(text:string): string {
    if(text=="黑") {
      return "#000000";
    }else if(text=="黄") {
      return "#FFAB00";
    }else if(text=="绿") {
      return "#10B568";
    }else if(text=="红") {
      return "#941010";
    }else if(text=="蓝") {
      return "#539be2";
    }else if(text=="褐") {
      return "#A0522D";
    }else{
      return "#000000";
    }
  }
  static hexToRgb(val:string): string {
    var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
    var color = val.toLowerCase();
    var result = '';
    if (reg.test(color)) {
      // 如果只有三位的值，需变成六位，如：#fff => #ffffff
      if (color.length === 4) {
        var colorNew = "#";
        for (var i = 1; i < 4; i += 1) {
          colorNew += color.slice(i, i + 1).concat(color.slice(i, i + 1));
        }
        color = colorNew;
      }
      // 处理六位的颜色值，转为RGB
      var colorChange = [];
      for (var i = 1; i < 7; i += 2) {
        colorChange.push(parseInt("0x" + color.slice(i, i + 2)));
      }
      return "rgb(" + colorChange.join(",") + ")";
    } else {
      return "rgb(0,0,0)";
    }
  }
}
